import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
Vue.use(ElementUI)
import VueLazyload from "vue-lazyload" //用法 特别是样式看这里http://www.jianshu.com/p/443a2d7c7bd5
Vue.use(VueLazyload, {
  error: './static/img/null.png', //这个是请求失败后显示的图片
  loading: './static/img/imgLoad.png', //这个是加载的loading过渡效果
})

import 'element-ui/lib/theme-default/index.css'


import { Swipe, SwipeItem } from 'vue-swipe';
require('vue-swipe/dist/vue-swipe.css');
Vue.component('swipe', Swipe);
Vue.component('swipe-item', SwipeItem);

import InfiniteLoading from 'vue-infinite-loading';

import VueAwesomeSwiper from 'vue-awesome-swiper';
require('swiper/dist/css/swiper.css')
import { swiper, swiperSlide } from 'vue-awesome-swiper'

import $bw from './common/$bw.js'
Vue.prototype.$bw = $bw;

import $toast from './common/toast.js'
import './common/toast.css'
Vue.prototype.$toast = $toast;

import utils from './common/utils.js'
Vue.prototype.$utils = utils

import axios from 'axios'

//测试本地
Vue.prototype.$wxHref = 'http://39.108.111.101:8655/yls/'
Vue.prototype.$http = 'http://39.108.111.101:8654';

//上线服务器端口
//Vue.prototype.$http = 'http://api.cdtx.org:81'
//Vue.prototype.$wxHref = 'http://qpzx.cdtx.org/#/'


Vue.prototype.$service = function(url, type, params) {
  type = type.toLowerCase()
  axios.defaults.headers.post['Content-Type'] = 'application/json; charset=utf-8'
  // var userInfo = this.$bw.getSto
  // rage("userInfo")
  // var token = ''
  // if (userInfo) {
  //   token = userInfo.AccessToken
  // }
  axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
  axios.defaults.headers.common['ClientType'] = 'Phone '
  return new Promise((resolve, reject) => {
    axios[type](Vue.prototype.$http + url, params)
      .then(response => {
        if (response.data.Status === 1) {
          resolve(response.data)
        } else {
          reject(response.data)
        }
      })
      .catch((error) => {
        console.info(error.response)
        if (error.response) {
          reject({ Message: error.response.Message })
        } else {
          reject({ Message: '网络错误' })
        }
      })
  })
}

import 'babel-polyfill'

Vue.config.productionTip = false

Vue.use(VueAwesomeSwiper)

import wcSwiper from 'wc-swiper'
import 'wc-swiper/style.css'
Vue.use(wcSwiper);
/* eslint-disable no-new */
let bw = new Vue({
  data() {
    return { rootInfo: { showHeader: true, showFooter: true, isPhone: false, activeAction: window.location.hash ? window.location.hash : '/index' } }
  },
  el: '#app',
  router,
  template: '<App :rootInfo="rootInfo"/>',
  components: {
    App,
    swiper,
    swiperSlide,
    InfiniteLoading,
  }
})
Vue.prototype.$bwMsg = function(val) {
  bw.$message(val)
}
